/**
 * make button
 * Copyright (c) 2009 cmiscm.com
 * date of final modification : 2008. 08. 24 
*/
package com.cmiscm.utils.display
{
	import com.cmiscm.utils.common.DisplayObjectUtilities;	
	import flash.display.Sprite;

	/**
	 * Make Button.
	 * 
	 * @example
 	 * <listing> 
 	 * package {
     *    import flash.display.Sprite;
     *    import com.cmiscm.utils.display.MakeButton;
     *    import flash.events.Event;
     *    
     *    public class TestError extends Sprite
     *    {
     *        public function TestError()
     *        {
     *             super();
     *             this.addEventListener(Event.ADDED_TO_STAGE, onAdd);
     *         }
     * 
     *         private function onAdd(evt:Event):void
     *         {
     *             evt.currentTarget.removeEventListener(evt.type, arguments.callee);
     * 
     *             var button:MakeButton = new MakeButton(300, 100);
     *             this.addChild(button);
     *        }
     *    }
     * }
     * </listing> 
     * 
     */	     
	public class MakeButton extends Sprite
	{
		private var _button:Sprite = new Sprite();
		
		public function MakeButton($tw:int, $th:int, $cursor:Boolean=true, $debug:Boolean=false)
		{
			super();
			setting($tw, $th, $cursor, $debug);
		}
		private function setting($tw:int, $th:int, $cursor:Boolean, $debug:Boolean):void
		{
			_button.graphics.beginFill(0xff0000, 0.4);
			_button.graphics.drawRect(0, 0, $tw, $th);
			_button.graphics.endFill();
			
			if (!$debug) DisplayObjectUtilities.hitArea(this, _button, $cursor);
			
			this.addChild(_button);
		}
		
		/**
		 * Return button 
		 * @return 
		 * 
		 */		
		public function get button():Sprite
		{
			return _button;
		}
		
		/**
		 * Destroy
		 * 
		 */		
		public function destroy():void
		{
			_button.graphics.clear();
			this.removeChild(_button);
			_button = null;
		}
		
	}
}